<?php

class StatusesResource extends BaseResource
{
    public function initialize()
    {
        $this->before_filters->skip('specified_user_must_be_authenticated_user',
                                    array('only' => 'get'));
    }
    
    public function get()
    {
        $statuses = $this->user->statuses->limit(20)->order_by('-timestamp');
        $this->responds($statuses, 200);
    }
    
    public function post()
    {
        $status = new Status();
        $status->text = $this->params['text'];
        $status->sender_id = $this->user->id;
        
        if ($status->save()) {
            // nous rechargeons le statut afin de disposer du champ 'timestamp'
            $status->reload();
            $this->responds_created($status, 201);
        } else {
            $this->responds_detailed_error($status->errors, 400);
        }
    }
}

?>